package com.vpclub.utils;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;

import java.util.Arrays;

/**
 * @author : leimingchao
 * @version V1.0
 * @Project: springdemo
 * @Package com.vpclub.utils
 * @Description: TODO
 * @date Date : 2021年06月06日 13:14
 */

public class BValidateAspect {

    public void logStart(JoinPoint joinPoint) {
        //获取目标方法运行时使用的参数
        Object[] args = joinPoint.getArgs();
        //获取到方法签名
        Signature signature = joinPoint.getSignature();
        String name = signature.getName();
        System.out.println("[ValidateAspect-前置通知]【" + name + "】方法开始执行，用的参数列表【" + Arrays.asList(args) + "】");
    }

    public static void logReturn(JoinPoint joinPoint, Object result) {
        Signature signature = joinPoint.getSignature();
        String name = signature.getName();
        System.out.println("[ValidateAspect-返回通知]【" + name + "】方法正常执行完成，计算结果是：" + result);
    }

    public static void logException(JoinPoint joinPoint, Exception exception) {
        Signature signature = joinPoint.getSignature();
        String name = signature.getName();
        System.out.println("[ValidateAspect-异常通知]【" + name + "】方法执行出现了异常，异常信息是【" + exception + "】");
    }

    /**
     * 想在目标方法执行结束的时候执行
     */
    private int logEnd(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        String name = signature.getName();
        System.out.println("[ValidateAspect-后置通知]【" + name + "】方法最终结束");
        return 0;
    }
}
